Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: react native adjustments #2229

Merged
merged 2 commits into from
Dec 10, 2023

Conversation

maschad
Copy link
Member

@maschad maschad commented Nov 10, 2023

@achingbrain achingbrain changed the base branch from release-v1.0 to master November 15, 2023 09:34
@achingbrain achingbrain force-pushed the main branch 2 times, most recently from 2697619 to 3dee5df Compare November 17, 2023 16:53
@maschad maschad force-pushed the feat/react-native-adjustments branch from 9664933 to 1a537ee Compare November 27, 2023 20:40
@achingbrain achingbrain force-pushed the main branch 26 times, most recently from cd16f4b to 6bb459f Compare November 29, 2023 19:10
@achingbrain achingbrain force-pushed the main branch 8 times, most recently from 242fd96 to bca8d6e Compare November 30, 2023 21:12
@achingbrain achingbrain changed the title feat: react native adjustments fix: react native adjustments Dec 7, 2023
@achingbrain
Copy link
Member

Progress!

image

@achingbrain
Copy link
Member

This is the app, very basic so far: https://github.com/ipfs-shipyard/js-libp2p-react-native

@achingbrain
Copy link
Member

Oh good, react native doesn't support passing async generators to for await..of, fun times - facebook/react-native#27432

@achingbrain
Copy link
Member

Actually it sort of does but generators don't appear to have the Symbol.asyncIterator property.

@achingbrain
Copy link
Member

The crypto situation is pretty dire, from what I can gather there's no SubtleCrypto support and Facebook's response to questions about adding it were lukewarm.

This rules out simply following the browser path in modules with node/browser support since they depend on SubtleCrypto.

We could shim in pure-js versions of everything but crypto is such a bottleneck for us that doing everything in js on your phone is likely to melt it.

The community response yielded react-native-webcrypto but it's incomplete and only works on Android.

react-native-webview-crypto is an interesting hack though the library it depends on has a showstopping bug that's only had a PR to fix it open for three years. It also involves stringifying and copying all data to be encrypted/decryped to/from a webview - I haven't measured it but common sense says that will not be a performant approach.

We could patch the library to fix the bug and transfer the Uint8Arrays but that will break clever memory optimisations elsewhere because the underlying Uint8Arrays will become unusable after the transfer.


The other approach is to follow the node path instead and use rn-nodeify to shim node core modules in where necessary.

This opens up the possibility of using react-native-quick-crypto which does crypto in C/C++ so would be preferable.

Unlike most of the other crypto libraries here, quick-crypto appears to still be under development so that's heartening.

@achingbrain achingbrain force-pushed the feat/react-native-adjustments branch from 0e561b0 to f828e4c Compare December 9, 2023 10:33
@achingbrain
Copy link
Member

Actually the sweet spot might be to shim SubtleCrypto with @peculiar/webcrypto - it uses node's crypto module internally which can then be resolved to react-native-quick-crypto.

@achingbrain
Copy link
Member

Getting there, it can dial the bootstrappers now:

image

@achingbrain
Copy link
Member

Circuit relay works:

image

- export typed event emitter separately from setMaxListeners
- update react-native overrides in module package.json files
- add react-native-webrtc implementation to WebRTC transport
@achingbrain achingbrain force-pushed the feat/react-native-adjustments branch from 122e420 to 4f63edb Compare December 10, 2023 08:34
@achingbrain achingbrain marked this pull request as ready for review December 10, 2023 12:54
@achingbrain achingbrain requested a review from a team as a code owner December 10, 2023 12:54
@achingbrain achingbrain merged commit 3415811 into libp2p:main Dec 10, 2023
22 checks passed
This was referenced Dec 10, 2023
This was referenced Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants